package com.test.project.system.pingwei.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.test.framework.aspectj.lang.enums.BusinessType;
import com.test.project.system.pingwei.domain.TPingwei;
import com.test.project.system.pingwei.service.ITPingweiService;
import com.test.project.system.user.domain.User;
import com.test.project.system.user.service.IUserService;
import com.test.framework.web.controller.BaseController;
import com.test.framework.web.domain.AjaxResult;
import com.test.common.utils.poi.ExcelUtil;
import com.test.framework.web.page.TableDataInfo;

/**
 * 比赛评委Controller
 * 
 * @author test
 * @date 2023-12-05
 */
@Controller
@RequestMapping("/system/pingwei")
public class TPingweiController extends BaseController
{
    private String prefix = "system/pingwei";

    @Autowired
    private ITPingweiService tPingweiService;
    

    @Autowired
    private IUserService userService;

    @GetMapping()
    public String pingwei()
    {
        return prefix + "/pingwei";
    }

    /**
     * 查询比赛评委列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TPingwei tPingwei)
    {
        startPage();
        List<TPingwei> list = tPingweiService.selectTPingweiList(tPingwei);
        return getDataTable(list);
    }

    /**
     * 导出比赛评委列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TPingwei tPingwei)
    {
        List<TPingwei> list = tPingweiService.selectTPingweiList(tPingwei);
        ExcelUtil<TPingwei> util = new ExcelUtil<TPingwei>(TPingwei.class);
        return util.exportExcel(list, "pingwei");
    }

    /**
     * 新增比赛评委
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
    	User u  = new User();
    	u.setRoleId(3L);
    	List<User> list = userService.selectUserList(u);
    	mmap.put("list", list);
        return prefix + "/add";
    }

    /**
     * 新增保存比赛评委
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TPingwei tPingwei)
    {
        return toAjax(tPingweiService.insertTPingwei(tPingwei));
    }

    /**
     * 修改比赛评委
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TPingwei tPingwei = tPingweiService.selectTPingweiById(id);
        mmap.put("tPingwei", tPingwei);
        return prefix + "/edit";
    }

    /**
     * 修改保存比赛评委
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TPingwei tPingwei)
    {
        return toAjax(tPingweiService.updateTPingwei(tPingwei));
    }

    /**
     * 删除比赛评委
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tPingweiService.deleteTPingweiByIds(ids));
    }
}
